let SiteController = exports;

SiteController.index = async function(ctx) {
    console.log('**********************************')
    await ctx.render('index', {
        name: 'Node Example! ',
        authUser: ctx.session.authUser,
        locales: ctx.i18n.__('locales.zh-CN')
    });
};

SiteController.logout = async function(ctx) {
    if (!ctx.session.authUser || ctx.session.authUser.isGuest) {
        ctx.redirect('/');
        return;
    }
    delete ctx.session.authUser;
    ctx.cookies.remove('futu.sid');
    ctx.cookies.remove('futu.sid.sig');
    let refer = encodeURIComponent(ctx.getHomeUrl());
    ctx.redirect(`http://passport.oa.com/site/logout.html?returnUrl=${refer}`);
};

SiteController.NotFound = async function (ctx) {
    await ctx.render('404');
};

SiteController.InternalError = async function (ctx) {
    await ctx.render('500', {
        msg: '内部错误'
    });
};
